<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
    $(function () {
        let id = sessionStorage.getItem("cookStyleUpdateId");
        if (id !== "null") {
            getCookStyleById(id);
            sessionStorage.setItem("cookStyleUpdateId", null);
        }
    });


    function getCookStyleById(id) {
        let data = myAjax("cookStyleById", {id: id}, "get");
        console.log(data);
        $("#cookStyleId").val(data[0].id);
        $("#cookStyleName").val(data[0].name);
        $("#cookStyleContent").val(data[0].content);
    }
    function saveNews() {
        let id = $("#cookStyleId").val();
        let name = $("#cookStyleName").val();
        let content = $("#cookStyleContent").val();
        let data = {
            method: id == "" ? "add" : "update",
            id: id,
            name: name,
            content: content,
        };
        myAjax("cookStyleUpdate", data, "get");
    }
</script>
<body>
<div><input type="text" value="" readonly id="cookStyleId"></div>
<div>名称：<input type="text" id="cookStyleName"></div>
<div>描述：<input type="text" id="cookStyleContent"></div>
<div><input type="button" value="保存" onclick="saveNews()"></div>

</body>
</html>